<template>
    <div class="attendance-list">
        <Table :columns="columns1" :data="datalist" :loading="tableload" highlight-row  :height="tableHeight"></Table>
        <vue-easy-print tableShow ref="dutymoduleadmindata" >
            <table v-show="printing" cellspacing="0" cellpadding="0" style="width:100%;color: #515a6e;text-align: center;border: 1px solid #e8eaec!important;">
                <thead style="background-color: #f8f8f8;">
                    <tr>
                        <th style="padding: 10px;border: 1px solid #e8eaec!important;">教师姓名</th>
                        <th style="padding: 10px;border: 1px solid #e8eaec!important;">正常签到数</th>
                        <th style="padding: 10px;border: 1px solid #e8eaec!important;">迟到数</th>
                        <th style="padding: 10px;border: 1px solid #e8eaec!important;">迟到扣分</th>
                        <th style="padding: 10px;border: 1px solid #e8eaec!important;">请假数</th>
                        <th style="padding: 10px;border: 1px solid #e8eaec!important;">旷工数</th>
                        <th style="padding: 10px;border: 1px solid #e8eaec!important;">旷工扣分</th>
                        <th style="padding: 10px;border: 1px solid #e8eaec!important;" v-if="columnstype=='semester' && typeall=='semester'">旷工扣钱数</th>
                        <th style="padding: 10px;border: 1px solid #e8eaec!important;">是否借调人员</th>
                    </tr>
                </thead>
                <tbody v-for="(item, index) in datalist" :key="index">
                    <tr>
                        <td style="padding: 10px;border: 1px solid #e8eaec!important;">{{ item.teacher_name.zh?item.teacher_name.zh:item.teacher_name.mn }}</td>
                        <td style="padding: 10px;border: 1px solid #e8eaec!important;">{{ item.normal }}</td>
                        <td style="padding: 10px;border: 1px solid #e8eaec!important;">{{ item.late }}</td>
                        <td style="padding: 10px;border: 1px solid #e8eaec!important;">{{ item.late_score }}</td>
                        <td style="padding: 10px;border: 1px solid #e8eaec!important;">{{ item.leave }}</td>
                        <td style="padding: 10px;border: 1px solid #e8eaec!important;">{{ item.kuanggong }}</td>
                        <td style="padding: 10px;border: 1px solid #e8eaec!important;">{{ item.kuanggong_score }}</td>
                        <td style="padding: 10px;border: 1px solid #e8eaec!important;" v-if="columnstype=='semester' && typeall=='semester'">{{ '¥ '+item.kuanggong_money }}</td>
                        <td style="padding: 10px;border: 1px solid #e8eaec!important;">{{ item.type ==1 ? '是' : '' }}</td>
                    </tr>
                </tbody>
            </table>
        </vue-easy-print>
    </div>
</template>

<script>   
    export default {
        props: {
            datalist: {
                type: [Boolean,Object,Array],
                default: false
            },
            tableHeight: {
                type: [Number],
                default: 0
            },
            tableload: {
                type: [Boolean],
                default: false
            },
            columnstype: {
                type: [Boolean,String],
                default: false
            },
            // 判断教师考勤统计、学期时显示旷工扣钱数
            //判断部门人员考勤统计和我的考勤数据不管是月份还是学期都不显示旷工扣钱数
            typeall: {
                type: [Boolean,String],
                default: false
            },
            printing: {
                type: [Boolean],
                default: false
            },
        },
    data () {
        return {
            columns1:[],
            columns3: [
                {
                    title: "教师姓名",
                    render:(h,params)=> {
                        return h('span',params.row.teacher_name?params.row.teacher_name.zh?params.row.teacher_name.zh:params.row.teacher_name.mn:'')
                    },
                    width: 140,
                    fixed: "left"
                },
                
                {
                    title: "正常签到数",
                    width: 120,
                    align: "center",
                    key: "normal",
                },
                {
                    title: "迟到数",
                    width: 100,
                    align: "center",
                    key: "late",
                },
                {
                    title: "迟到扣分",
                    width: 120,
                    align: "center",
                    key: "late_score",
                },
                {
                    title: "请假数",
                    width: 100,
                    align: "center",
                    key: "leave",
                },
                {
                    title: "旷工数",
                    key: "kuanggong",
                    align: "center",
                    width: 100,
                },
                {
                    title: "旷工扣分",
                    key: "kuanggong_score",
                    align: "center",
                    width: 120
                },
                {
                    title: "是否借调人员",
                    width: 170,
                    align: "center",
                    render: (h, params) => {
                        let str = params.row.type==1 ? '是' : '否'
                        return h("div",str);
                    }
                },
                {
                    title: " ",
                },
                {
                    title: "操作",
                    key: "action",
                    width: 80,
                    align: "center",
                    fixed: "right",
                    render: (h, params) => {
                        return h("div", [
                            h(
                                "Button",
                                {
                                    props: {
                                        type: "success",
                                        size: "small"
                                    },
                                    style: {
                                        marginRight: "5px"
                                    },
                                    on: {
                                        click: () => {
                                            this.Detail(params.row);
                                        }
                                    }
                                },
                                "查看"
                            ),
                        ]);
                    }
                }
            ],
            columns2: [
                {
                    title: "教师姓名",
                    render:(h,params)=> {
                        return h('span',params.row.teacher_name?params.row.teacher_name.zh?params.row.teacher_name.zh:params.row.teacher_name.mn:'')
                    },
                    width: 140,
                    fixed: "left"
                },
                
                {
                    title: "正常签到数",
                    width: 120,
                    align: "center",
                    key: "normal",
                },
                {
                    title: "迟到数",
                    width: 100,
                    align: "center",
                    key: "late",
                },
                {
                    title: "迟到扣分",
                    width: 120,
                    align: "center",
                    key: "late_score",
                },
                {
                    title: "请假数",
                    width: 100,
                    align: "center",
                    key: "leave",
                },
                {
                    title: "旷工数",
                    key: "kuanggong",
                    align: "center",
                    width: 100,
                },
                {
                    title: "旷工扣分",
                    key: "kuanggong_score",
                    align: "center",
                    width: 120
                },
                // this.typeall=='semester'
                {
                    title: "旷工扣钱数",
                    align: "center",
                    width: 120,
                    render: (h, params) => {
                        let str = '¥ '+params.row.kuanggong_money
                        return h("div",str);
                    }
                },
                {
                    title: "是否借调人员",
                    width: 170,
                    align: "center",
                    render: (h, params) => {
                        let str = params.row.type==1 ? '是' : ''
                        return h("div",str);
                    }
                },
                {
                    title: " ",
                },
            ],
            columns4: [
                {
                    title: "教师姓名",
                    render:(h,params)=> {
                        return h('span',params.row.teacher_name?params.row.teacher_name.zh?params.row.teacher_name.zh:params.row.teacher_name.mn:'')
                    },
                    width: 140,
                    fixed: "left"
                },
                
                {
                    title: "正常签到数",
                    width: 120,
                    align: "center",
                    key: "normal",
                },
                {
                    title: "迟到数",
                    width: 100,
                    align: "center",
                    key: "late",
                },
                {
                    title: "迟到扣分",
                    width: 120,
                    align: "center",
                    key: "late_score",
                },
                {
                    title: "请假数",
                    width: 100,
                    align: "center",
                    key: "leave",
                },
                {
                    title: "旷工数",
                    key: "kuanggong",
                    align: "center",
                    width: 100,
                },
                {
                    title: "旷工扣分",
                    key: "kuanggong_score",
                    align: "center",
                    width: 120
                },
                {
                    title: "是否借调人员",
                    width: 170,
                    align: "center",
                    render: (h, params) => {
                        let str = params.row.type==1 ? '是' : ''
                        return h("div",str);
                    }
                },
                {
                    title: " ",
                },
            ],
        }
    },
    methods: {
        Detail(row){
            let obj = {
                user_id:row.user_id,
                titles:row.teacher_name.zh,
                isShow:true
            }
            this.$emit('on-look-fun',obj);
        },

        
        /************************************************************
         * 
         * 打印数据
         * 
         ************************************************************/
        printingClick () { 
            this.$nextTick(_=>{
                this.$refs.dutymoduleadmindata.print()
                this.$emit('print-end',false);
            })
        },
    },
    mounted(){
        if(this.columnstype=='semester'){
            if(this.typeall=='semester'){
                this.columns1=this.columns2
            }else{
                this.columns1=this.columns4
            }
        }else{
            this.columns1=this.columns3
        }
    },
    watch:{
        'columnstype':function (val) {
            if(this.columnstype=='semester'){
                if(this.typeall=='semester'){
                    this.columns1=this.columns2
                }else{
                    this.columns1=this.columns4
                }
            }else{
                this.columns1=this.columns3
            }
        },
        'printing':function (val) {
            if(this.printing==true){
                this.printingClick()
            }
        },
       
    }

  }
</script>

<style lang="less">
.attendance-list{
    position: relative;
    
}
</style>
